<template>
<UserForm @onSubmit="onSubmit"/>
</template>

<script>
import { loginAPI } from '@/api/user'
import UserForm from '@/components/UserForm.vue'
import { setToken } from '@/utils/storage'

export default {
  name: 'LoginPage',
  components: {
    UserForm
  },
  methods: {

    async onSubmit (values) {
      // 3. 封装登录API 调用登录接口
      const res = await loginAPI(values)
      // 4.登录成功 : 提示用户 存token 跳转到首页
      this.$toast('登录成功')
      setToken(res.data.token)
      this.$router.push('/')
    }
  }

}
</script>

<style lang="scss" scoped>

</style>
